package com.chujian.Adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chujian.model.CurrentOrderBean;
import com.chujian.model.Order;
import com.chujian.orderingsystem.R;

public class OrderCurrentListAdapter extends BaseAdapter{
	private LayoutInflater mLayoutInflater;
	private Context context;
//	private List<CurrentOrderBean> mList;
	private List<Order> mList;
	public OrderCurrentListAdapter(Context context, List<Order> mList) {
		super();
		this.context = context;
		this.mList = mList;
		mLayoutInflater=LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder=null;
		if(convertView==null){
			holder=new ViewHolder();
			convertView=mLayoutInflater.inflate(R.layout.order_current_list_item, null);
			holder.tvId=(TextView) convertView.findViewById(R.id.tv_order_current_list_item_id);
			holder.tvTable=(TextView) convertView.findViewById(R.id.tv_order_current_list_item_table);
			holder.tvTime=(TextView) convertView.findViewById(R.id.tv_order_current_list_item_time);
			holder.tvUser=(TextView) convertView.findViewById(R.id.tv_order_current_list_item_phone);
			holder.tvPrice=(TextView) convertView.findViewById(R.id.tv_order_current_list_item_price);
			convertView.setTag(holder);
		}else{
			holder=(ViewHolder) convertView.getTag();
		}
		holder.tvId.setText(mList.get(position).getOrderId()+"");
		holder.tvPrice.setText(mList.get(position).getTotalPrice()+"元");
		holder.tvTable.setText(mList.get(position).getTableName());
		holder.tvUser.setText(mList.get(position).getUserPhone());
		SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
		long millis=Long.parseLong(mList.get(position).getOrderTime());
		Log.i("info", millis+"");
		String dateTime = dateFm.format(new java.util.Date(millis));
		holder.tvTime.setText(dateTime);
		return convertView;
	}
	class ViewHolder{
		public TextView tvId;
		public TextView tvTable;
		public TextView tvTime;
		public TextView tvUser;
		public TextView tvPrice;
	}
}

